import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import ELementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import axios from 'axios';
//前端mock测试
import './mock'
// 定义根路径
axios.defaults.baseURL = 'http://127.0.0.1:8000';
//为axios添加拦截器
axios.interceptors.request.use(config => {
    const token = window.sessionStorage.getItem('token');
    if (token) {
        config.headers.Authorization = `Bearer ${token}`;
    }
    return config;
}, error => {
    return Promise.reject(error);
});
const app = createApp(App)
    // 使用 provide 来全局注入 axios
app.config.globalProperties.$http = axios;
app.use(ELementPlus)
app.use(router)
app.mount('#app')
console.log('Vue 3 应用已经成功初始化');

const debounce = (fn, delay) => {
    let timer = null;
    return function () {
        let context = this;
        let args = arguments;
        clearTimeout(timer);
        timer = setTimeout(function () {
            fn.apply(context, args);
        }, delay);
    }
}

const _ResizeObserver = window.ResizeObserver;
window.ResizeObserver = class ResizeObserver extends _ResizeObserver{
    constructor(callback) {
        callback = debounce(callback, 16);
        super(callback);
    }
}


